const readline = require('readline-sync');
//登录注册

let users = [
    ['zhangsan', 123],
    ['lisi', 456]
];
let login = false;
let login3 = false;
let xunhuan = true;
let xunhuan2 = true;
let money = 500;
while (xunhuan2) {
    console.log('请选择：1. 登录 2. 注册');
    let opt = readline.question() - 0;
    switch (opt) {
        case 1:
            console.log('请输入账号');
            let id = readline.question();
            console.log('请输入密码');
            let password = readline.question();
            for (let item of users) {
                if (id == item[0] && password == item[1]) {
                    login = true;
                }
            }
            if (login) {
                console.log(`欢迎你${id}`);
                xunhuan2 = false;
                login3 = true;
            }
            break;

        case 2:
            while (xunhuan) {
                console.log('请输入注册账号');
                let id = readline.question();
                let login2 = false;
                for (let item of users) {
                    if (id == item[0]) {
                        login2 = true;
                    }
                }
                if (login2) {
                    console.log('账号已经被注册');
                    xunhuan = true;
                } else {
                    console.log('请输入注册密码');
                    let password = readline.question();
                    users.push[[id, password]];
                    xunhuan = false;

                }
            }

            break;
    }
}
while (login3) {
    console.log('1存钱 2取钱 3查钱 4退卡');
    let number = Number(readline.question());
    switch (number) {
        case 1:
            console.log('请输入存款余额');
            let deposit = Number(readline.question());
            console.log(`${money+=deposit}`);
            console.log('返回上级,请按“1”');
            let oo = readline.question();
            // login: true;
            break;
        case 2:
            console.log('请输入取款余额');
            let Withdrawal = Number(readline.question());
            if (Withdrawal > money) {
                console.log('余额不足');
            } else(console.log(`${money -= Withdrawal}`));
            console.log('返回上级,请按“1”');
            let ll = readline.question();
            // login: true;
            break;
        case 3:
            console.log(money);
            console.log('返回上级,请按“1”');
            let uu = readline.question();
            // login: true;
            break;
        case 4:
            console.log('再见');
            login = false;
            break;
    }
}